﻿using UnityEngine;

public class CrystalSkill:CloneBaseSkill
{
    public bool hasCrystal;
    public CrystalSkill(string skillName) : base(skillName)
    {
        //监听被动销毁
        EventCenter.Instance.AddEventListener(E_EventType.Crystal_Finish_Destroy,CrystalDestroy);
    }

    private void CrystalDestroy()
    {
        hasCrystal = false;
        StopSkillDuration();
    }

    public override void Update()
    {
        base.Update();
        //时间到触发主动销毁
        if (hasCrystal && skillDuration<=0)
        {
            hasCrystal = false;
            EventCenter.Instance.EventTrigger(E_EventType.Crystal_Active_Destroy);
        }
    }


    public override CloneController Clone(string prefab, Vector2 pos, int faceDir)
    {
        hasCrystal = true;
        var  cloneController = base.Clone(prefab,pos,faceDir);
        var  crystalController =  cloneController as CrystalCloneController;
        if (crystalController!=null)
        {
            if (skillName.Equals(Setting.SkillExplosiveCrystal))
            {
                crystalController.CanExplosion();//允许爆炸
            }else if (skillName.Equals(Setting.SkillCloneCrystal))
            {
                crystalController.CanClone();//允许克隆分身
            }else if (skillName.Equals(Setting.SkillNbombCrystal))
            {
                crystalController.CanNbomb();//允许次核爆炸
            }
        }
        return cloneController;
    }
    
    public override void OnDestroy()
    {
        EventCenter.Instance.RemoveEventListener(E_EventType.Crystal_Finish_Destroy,CrystalDestroy);
    }
}